package org.huawei260.TiKu.ODsuanfa;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author: qingle
 * @Date: 2024/10/28-16:11
 * @Description: 2527 【模拟】2024D结队编程
 * @version: 1.0
 */
public class D_2024D_2527__模拟结队编程_answer {

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			int n = Integer.parseInt(sc.nextLine());
			int[] levels = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

			System.out.println(getResult(n, levels));
		}

		public static long getResult(int n, int[] levels) {
			long ans = 0;

			for (int i = 1; i < n - 1; i++) {
				int mid = levels[i];

				long leftSmallerCount = 0;
				long leftBiggerCount = 0;

				for (int j = 0; j < i; j++) {
					if (levels[j] > mid) {
						leftBiggerCount++;
					} else {
						leftSmallerCount++;
					}
				}

				long rightSmallerCount = 0;
				long rightBiggerCount = 0;

				for (int k = i + 1; k < n; k++) {
					if (levels[k] > mid) {
						rightBiggerCount++;
					} else {
						rightSmallerCount++;
					}
				}

				ans += leftSmallerCount * rightBiggerCount + leftBiggerCount * rightSmallerCount;
			}

			return ans;
		}
	}